package com.evaluity;


import android.os.Bundle;
import android.os.StrictMode;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class CentralActivity extends Activity {
	
	private Activity activity;
	
	public void startAssistentsActivity() {
		
		Intent i = new Intent(this, Geolog.class);
		//i.putExtra(Constants.EXTRA_ACTIVITY, Constants.ASSISTENTS_ACTIVITY);
		startActivity(i);
	}
	
	public void startAssistentsActivity2() {
		
		Intent i = new Intent(this, GetAcount.class);
		//i.putExtra(Constants.EXTRA_ACTIVITY, Constants.ASSISTENTS_ACTIVITY);
		startActivity(i);
	}
	
	public void startAssistentsActivity3() {
		
		Intent i = new Intent(this, Login.class);
		//i.putExtra(Constants.EXTRA_ACTIVITY, Constants.ASSISTENTS_ACTIVITY);
		startActivity(i);
	}
	
	public void startAssistentsActivityCentral() {
		
		Intent i = new Intent(this, CentralActivity.class);
		//i.putExtra(Constants.EXTRA_ACTIVITY, Constants.ASSISTENTS_ACTIVITY);
		startActivity(i);
	}


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		final Usuario usuario = new Usuario();
	      if(usuario.isUserLoggedIn(this)){
	         usuario.readUser(this);
	      	System.out.println(usuario.getEmail());
	      } else 
	    	   startAssistentsActivity3();
	      
	      activity = this;
	      
		setContentView(R.layout.activity_central);
		
		if (android.os.Build.VERSION.SDK_INT > 9) {
		      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
		      StrictMode.setThreadPolicy(policy);
		    }
		
		Button assistButton = (Button) findViewById(R.id.addDegree);
        assistButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				startAssistentsActivity();
			}
		});
        
        Button assistButton2 = (Button) findViewById(R.id.getAcount);
        assistButton2.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				startAssistentsActivity2();
			}
		});
        
        Button assistButton3 = (Button) findViewById(R.id.login);
        assistButton3.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				startAssistentsActivity3();
			}
		});
        
        Button assistButton4 = (Button) findViewById(R.id.logout);
        assistButton4.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				usuario.logout(activity);
				startAssistentsActivityCentral();
			}
		});
        
        TextView text = (TextView) findViewById(R.id.textview);
        text.setText(usuario.getEmail());
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
